# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     container_num_post
   Description :
   Author :       'li'
   date：          2020/11/25
-------------------------------------------------
   Change Activity:
                   2020/11/25:
-------------------------------------------------
"""
import json
import os

import requests

import ml
from ml.cv.misc.img_io import write_img
from ml.cv.util.img_util import ImageTransform

ip = '127.0.0.1'


def main():
    paths = ml.list_file_paths_in_dir(rf"D:\test_img\铅封")
    for p in paths:
        # p = 'D:/image/道口箱号识别/success/MSKU_842043_2__True____24a14b2c565e48a48f3c021d2509f0eb.jpg'
        _, name = os.path.split(p)
        file = {'pic': open(p, 'rb')}
        res = requests.post(url=rf'http://{ip}:8080/ocr/seal_detect', data={'is_return_image': 'true'}, files=file)
        obj = json.loads(res.text)
        img = ImageTransform.base64_to_img(obj['image_base64'])
        write_img(img, rf'C:\Users\Administrator\Desktop\res/{name}')


if __name__ == '__main__':
    main()
